var ico,ic,ik; 
//菜单切换
$('#pro li').click(function () {
    $(this).addClass("greensy").siblings().removeClass("greensy");
    $('#tagpic>li').eq($(this).index()).addClass("greensy").siblings().removeClass("greensy");
});
//删除
 $('.delete').click(function () {
    var val = $(this).attr("value");
    var str = "/my/consultation_delet.jsp";
    $(window.parent.document).find("#sele").attr("str", str);
    $(window.parent.document).find("#confirm").attr("val", val);
    $(window.parent.document).find("#sele").show();
    $(window.parent.document).find('body').css({
        "overflow-x": "hidden",
        "overflow-y": "hidden"
    });
});
var login = new Validated();
login.blur().focus();
$('button').click(function(){
    ico = $('#ico').val().length;
    ic = $('#inp>input').length-1;
    if(ico!=0){
    new Ajax("consultation_net.jsp").keyvalue($('#form').serializeArray()).keyvalue("ic",ic).getJson(function(json){
            if (json === 1) {
                $(window.parent.document).find('body').css({
                    "overflow-x": "hidden",
                    "overflow-y": "hidden"
                });
                $(window.parent.document).find("#vague").show();
                $(window.parent.document).find("#pop").children('p').text("上传成功");
            };
            window.location.reload();
            $('input').val("");
    });
    }else{
        $(window.parent.document).find("#vague").show();
        $(window.parent.document).find("#pop").children('p').text("至少上传一张");
    }
});
//分页
var numb,firstpage,lastpage,nextpage,lastpage,txt,ptstate,color,key,cat;
var page=0;
var fengzi = $('#page a b').first();
var fengmu = $('#page a b').last();
query(1);
num();
$('#searchpt').click(function(){
    query(1);
    num();
})

//首页
    function first(){
        query(1);
        fengzi.text("1");
    }
//上一页    
    function previous(){
        var zi= parseInt(fengzi.text());
        var mu = parseInt(fengmu.text());
        if(zi>1){
        zi= zi-1;
        fengzi.text(zi);
        query(zi);
        }
    }
//下一页    
    function next(){
        var zi= parseInt(fengzi.text());
        var mu = parseInt(fengmu.text());
        if(zi<mu){
        zi= zi+1;
        fengzi.text(zi);
        query(zi);
        }
    }
//尾页    
    function last(){
        query(fengmu.text());
        fengzi.text(fengmu.text());
    } 
//跳转
  function jump(){
   var jump = $('[name=jump]').val();
   var mu = parseInt(fengmu.text());
   if(1<=jump&&jump<=mu){
        fengzi.text(jump);
        query(jump);
   }
  }    
function query(page) {
    $('#participation').empty();
    txt = "";
    new Ajax("/my/consultation_search.jsp").keyvalue({"page": page}).getJson(function (json) {
        $.each(json, function (key, val) {
            shijian = new Date(val["uptimes"] * 1000).toString().substring(0,10);
            txt = txt + "<tr class='content1'><td><img src='/upfile/"+val["certimg"]+"' style='width:150px;' alt=''/></td><td>"+shijian+"</td class='delete' value='"+val["id"]+"'><td class='delete' value='"+val["id"]+"'>删除</td></tr>"
        })
        $('#participation').html(txt);
        $(window.parent).scrollTop(0);
        $('#participation tr td.delete').click(function(){
        $(window.parent.document).find('#sele').show();
        $(window.parent.document).find('#sele').attr("str","/my/consultation_delet.jsp");
        $(window.parent.document).find('#confirm').attr("val",$(this).attr("value"));
})
    })
}
//总页数
 function num(){
        new Ajax("/my/consultation_page.jsp").get(function(data){
        numb = Math.ceil(data.replace(/[^0-9]/ig, "")/10);
        fengmu.text(numb);
    });
     fengzi.text("1");
    }